package awt;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class MyTest {
	public static void main(String args[]){
		JFrame w = new JFrame() ;
		w.setSize(300 , 400) ;
		
		MyPanel mp = new MyPanel() ;
		w.add(mp) ;
		
		Thread t = new Thread(mp);
		t.start();
		w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		w.setVisible(true);
	}
}

class MyPanel extends JPanel implements Runnable{
	int x=30;
	int y=0;
	
	public void paint(Graphics g){
		g.clearRect(0, 0, 300, 400);
		g.fillOval(x, y, 20, 20) ;
	}

	@Override
	public void run() {
		while(true) {
			y+=2;
			if(y>380) {
				y=0;
			}
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			repaint();
		}
		
	}
	
	
}